Update, Activate, and Resume Events
If the application receives an update event, it must update the currently active window. If the window corresponds to a frame, you must pass the update event to the frame using theJMFrameUpdate
function (page 88). The AWT context can then update the actual window using a callback. Listing 1-12 shows an example of an update function.Listing 1-12 Handling a frame update event
static void handleUpdate(WindowPtr win) { JMFrameRef frame; BeginUpdate(win); SetPort(win); frame = (JMFrameRef) GetWRefCon(win); if (frame) JMFrameUpdate(frame, win->visRgn); else EraseRgn(win->visRgn); EndUpdate(win); }If an activate event occurs, then a window was made active (that is, brought to the front), and if that window is associated with a frame, you must activate the frame using theJMFrameActivate
function (page 89). This action gives the frame the opportunity to highlight title bars, scroll bars, and so on. Activating a frame also installs the menu bar associated with the frame. Listing 1-13 gives an example of activating a frame.Listing 1-13 Sending an activate event to a frame
static void handleActivate(Boolean active, WindowPtr window) { JMFrameRef frame = (JMFrameRef) GetWRefCon(window); if (frame) JMFrameActivate(frame, active); }Similar to the activate event are the suspend and resume events, which can also occur when a window is activated or deactivated. When the user switches from one application to another, the newly selected application is sent a resume event, and the previously active one is sent a suspend event. This event affects all the applets embedded within an application, so you must call the
- Note
- The
JMFrameActivate
function can either activate or deactivate a frame depending on the Boolean value passed to it (the value ofactive
in this example).![]()
JMFrameResume
function (page 89) to suspend or resume all the existing frames.Listing 1-14 shows how to send a resume event to all the frames associated with a client application.
Listing 1-14 Sending a resume event to frames
static void handleResume(Boolean resume) { WindowPtr win = FrontWindow(); while (win) { JMFrameRef frame = (JMFrameRef) GetWRefCon(win); if (frame) JMFrameResume(frame, resume); win = (WindowPtr) ((WindowPeek) win)->nextWindow; } }This example cycles through all the visible windows used by the application and sends the event to those that are associated with frames. However, this example only works if every frame is associated with a window. If this is not the case, you must use some other method to send the resume event.
- Note
- The
JMFrameResume
function can either suspend or resume a frame depending on the Boolean value passed to it (the value ofresume
in this example).![]()